/**
 * 
 */
package co.fitstart.entity.coach;

import java.beans.Transient;
import java.util.List;

import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;

import co.fitstart.entity.principal.Principal;
import co.fitstart.entity.site.Site;

/**
 * @author downpour
 *
 */
@Entity
@Table(name = "principal_report_relation")
@JsonIgnoreProperties(value={"hibernate_lazy_initializer","handler","fieldHandler"})
public class PrincipalReportRelation {
    
    @Id
    @GeneratedValue
    private Long id;
    
    @ManyToOne(fetch = FetchType.LAZY, optional = true)
    private Principal coach;
    
    @ManyToOne(fetch = FetchType.LAZY, optional = true)
    private Principal manager;
    
    /** manager所管理门店 */
    @ManyToOne(fetch = FetchType.LAZY, optional = false)
    private Site site;
    
    /** 可预约日期 */
    private String appointDays;
    
    /** 可预约时间 */
    private String appointHours;
    
    /**
     * The default constructor
     */
    public PrincipalReportRelation() {
        
    }

    /**
     * The constructor using fields
     * 
     * @param coach
     * @param manager
     * @param site
     */
    public PrincipalReportRelation(Principal coach, Principal manager, Site site) {
        this.coach = coach;
        this.manager = manager;
        this.site = site;
    }
    
    /**
     * 
     * @param coach
     * @param site
     */
    public PrincipalReportRelation(Principal coach, Site site) {
        this.coach = coach;
        this.site = site;
    }
    
    /**
     * 
     * @param appointDays
     * @return
     */
    public PrincipalReportRelation editAppointDays(List<Integer> appointDays) {
        if(appointDays == null) {
            this.appointDays = null;
        } else {
            StringBuffer buffer = new StringBuffer();
            
            for(int appointDay : appointDays) {
                buffer.append(appointDay + ",");
            }
            
            this.appointDays = buffer.toString();
        }
        
        return this;
    }
    
    public PrincipalReportRelation editManager(Principal manager) {
        this.manager = manager;
        
        return this;
    }
    
    /**
     * 
     * @param site
     * @return
     */
    public PrincipalReportRelation editSite(Site site) {
        this.site = site;
        return this;
    }
    
    /**
     * 
     * @param appointHours
     * @return
     */
    public PrincipalReportRelation editAppointHours(List<String> appointHours) {
        if(appointHours == null) {
            this.appointHours = null;
        } else {
            StringBuffer buffer = new StringBuffer();           
            
            for(String appointHour : appointHours) {
                buffer.append(appointHour + ",");
            }
            
            this.appointHours = buffer.toString();
        }
        
        return this;
    }
    
    /**
     * 
     * @return
     */
    @Transient
    public String getAppointTime() {
        if(appointDays != null) {
            String[] temps = appointDays.split(",");
            
            if(temps != null && temps.length > 0) {
                StringBuffer buffer = new StringBuffer();
                
                for(String temp : temps) {
                    if("1".equals(temp)) {
                        buffer.append("周一，");
                    } else if("2".equals(temp)) {
                        buffer.append("周二，");
                    } else if("3".equals(temp)) {
                        buffer.append("周三，");
                    } else if("4".equals(temp)) {
                        buffer.append("周四，");
                    } else if("5".equals(temp)) {
                        buffer.append("周五，");
                    } else if("6".equals(temp)) {
                        buffer.append("周六，");
                    } else if("7".equals(temp)) {
                        buffer.append("周日，");
                    }
                }
                
                if(buffer.length() > 0) {
                    return buffer.substring(0, buffer.length() - 1);
                }
            }
        }
        return "周一至周日";
    }
    
    /**
     * 
     * @return
     */
    @Transient
    public String getAppointManyHour() {
    	
    	if(appointHours != null) {
    		
    		return appointHours.substring(0, appointHours.length()-1);
    	}
    	
    	return "";
    }

    /**
     * @return the id
     */
    public Long getId() {
        return id;
    }

    /**
     * @return the coach
     */
    public Principal getCoach() {
        return coach;
    }

    /**
     * @return the manager
     */
    public Principal getManager() {
        return manager;
    }

    /**
     * @return the site
     */
    public Site getSite() {
        return site;
    }

    /**
     * @return the appointDays
     */
    public String getAppointDays() {
        return appointDays;
    }

    /**
     * @param id the id to set
     */
    public void setId(Long id) {
        this.id = id;
    }

    /**
     * @param coach the coach to set
     */
    public void setCoach(Principal coach) {
        this.coach = coach;
    }

    /**
     * @param manager the manager to set
     */
    public void setManager(Principal manager) {
        this.manager = manager;
    }

    /**
     * @param site the site to set
     */
    public void setSite(Site site) {
        this.site = site;
    }

    /**
     * @param appointDays the appointDays to set
     */
    public void setAppointDays(String appointDays) {
        this.appointDays = appointDays;
    }

    /**
     * 
     * @return
     */
	public String getAppointHours() {
		return appointHours;
	}

	/**
	 * 
	 * @param appointHours
	 */
	public void setAppointHours(String appointHours) {
		this.appointHours = appointHours;
	}
    
    
    
}
